using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JlPay.Sdk.Models.Trans.Dto
{
    /// <summary>
    /// 终端信息DTO
    /// @author liaochangyi
    /// @since 2025-01-25
    /// </summary>
    public class TerminalInfoDto
    {
        /// <summary>
        /// 银行卡受理终端入网编号
        /// </summary>
        [JsonPropertyName("network_license")]
        public string? NetworkLicense { get; set; }

        /// <summary>
        /// 设备类型
        /// </summary>
        [JsonPropertyName("device_type")]
        public string? DeviceType { get; set; }

        /// <summary>
        /// 设备序列号
        /// </summary>
        [JsonPropertyName("serial_num")]
        public string? SerialNum { get; set; }

        /// <summary>
        /// 加密随机因子
        /// </summary>
        [JsonPropertyName("encrypt_rand_num")]
        public string? EncryptRandNum { get; set; }

        /// <summary>
        /// 密文数据
        /// </summary>
        [JsonPropertyName("secret_text")]
        public string? SecretText { get; set; }

        /// <summary>
        /// 终端应用版本号
        /// </summary>
        [JsonPropertyName("app_version")]
        public string? AppVersion { get; set; }

        /// <summary>
        /// 移动国家代码
        /// </summary>
        [JsonPropertyName("mobile_country_cd")]
        public string? MobileCountryCd { get; set; }

        /// <summary>
        /// 移动网络号码
        /// </summary>
        [JsonPropertyName("mobile_network_num")]
        public string? MobileNetworkNum { get; set; }

        /// <summary>
        /// ICCID
        /// </summary>
        [JsonPropertyName("icc_id")]
        public string? IccId { get; set; }

        /// <summary>
        /// 位置区域码 1
        /// </summary>
        [JsonPropertyName("location_cd1")]
        public string? LocationCd1 { get; set; }

        /// <summary>
        /// 基站编号 1
        /// </summary>
        [JsonPropertyName("lbs_num1")]
        public string? LbsNum1 { get; set; }

        /// <summary>
        /// 基站信号 1
        /// </summary>
        [JsonPropertyName("lbs_signal1")]
        public string? LbsSignal1 { get; set; }

        /// <summary>
        /// 位置区域码 2
        /// </summary>
        [JsonPropertyName("location_cd2")]
        public string? LocationCd2 { get; set; }

        /// <summary>
        /// 基站编号 2
        /// </summary>
        [JsonPropertyName("lbs_num2")]
        public string? LbsNum2 { get; set; }

        /// <summary>
        /// 基站信号 2
        /// </summary>
        [JsonPropertyName("lbs_signal2")]
        public string? LbsSignal2 { get; set; }

        /// <summary>
        /// 位置区域码 3
        /// </summary>
        [JsonPropertyName("location_cd3")]
        public string? LocationCd3 { get; set; }

        /// <summary>
        /// 基站编号 3
        /// </summary>
        [JsonPropertyName("lbs_num3")]
        public string? LbsNum3 { get; set; }

        /// <summary>
        /// 基站信号 3
        /// </summary>
        [JsonPropertyName("lbs_signal3")]
        public string? LbsSignal3 { get; set; }

        /// <summary>
        /// 电信系统识别码
        /// </summary>
        [JsonPropertyName("telecom_system_id")]
        public string? TelecomSystemId { get; set; }

        /// <summary>
        /// 电信网络识别码
        /// </summary>
        [JsonPropertyName("telecom_network_id")]
        public string? TelecomNetworkId { get; set; }

        /// <summary>
        /// 电信基站
        /// </summary>
        [JsonPropertyName("telecom_lbs")]
        public string? TelecomLbs { get; set; }

        /// <summary>
        /// 电信基站信号
        /// </summary>
        [JsonPropertyName("telecom_lbs_signal")]
        public string? TelecomLbsSignal { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public TerminalInfoDto()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="terminalDict">终端信息字典</param>
        public TerminalInfoDto(Dictionary<string, object>? terminalDict)
        {
            if (terminalDict != null)
            {
                NetworkLicense = terminalDict.TryGetValue("network_license", out var networkLicense) ? networkLicense?.ToString() : null;
                DeviceType = terminalDict.TryGetValue("device_type", out var deviceType) ? deviceType?.ToString() : null;
                SerialNum = terminalDict.TryGetValue("serial_num", out var serialNum) ? serialNum?.ToString() : null;
                EncryptRandNum = terminalDict.TryGetValue("encrypt_rand_num", out var encryptRandNum) ? encryptRandNum?.ToString() : null;
                SecretText = terminalDict.TryGetValue("secret_text", out var secretText) ? secretText?.ToString() : null;
                AppVersion = terminalDict.TryGetValue("app_version", out var appVersion) ? appVersion?.ToString() : null;
                MobileCountryCd = terminalDict.TryGetValue("mobile_country_cd", out var mobileCountryCd) ? mobileCountryCd?.ToString() : null;
                MobileNetworkNum = terminalDict.TryGetValue("mobile_network_num", out var mobileNetworkNum) ? mobileNetworkNum?.ToString() : null;
                IccId = terminalDict.TryGetValue("icc_id", out var iccId) ? iccId?.ToString() : null;
                LocationCd1 = terminalDict.TryGetValue("location_cd1", out var locationCd1) ? locationCd1?.ToString() : null;
                LbsNum1 = terminalDict.TryGetValue("lbs_num1", out var lbsNum1) ? lbsNum1?.ToString() : null;
                LbsSignal1 = terminalDict.TryGetValue("lbs_signal1", out var lbsSignal1) ? lbsSignal1?.ToString() : null;
                LocationCd2 = terminalDict.TryGetValue("location_cd2", out var locationCd2) ? locationCd2?.ToString() : null;
                LbsNum2 = terminalDict.TryGetValue("lbs_num2", out var lbsNum2) ? lbsNum2?.ToString() : null;
                LbsSignal2 = terminalDict.TryGetValue("lbs_signal2", out var lbsSignal2) ? lbsSignal2?.ToString() : null;
                LocationCd3 = terminalDict.TryGetValue("location_cd3", out var locationCd3) ? locationCd3?.ToString() : null;
                LbsNum3 = terminalDict.TryGetValue("lbs_num3", out var lbsNum3) ? lbsNum3?.ToString() : null;
                LbsSignal3 = terminalDict.TryGetValue("lbs_signal3", out var lbsSignal3) ? lbsSignal3?.ToString() : null;
                TelecomSystemId = terminalDict.TryGetValue("telecom_system_id", out var telecomSystemId) ? telecomSystemId?.ToString() : null;
                TelecomNetworkId = terminalDict.TryGetValue("telecom_network_id", out var telecomNetworkId) ? telecomNetworkId?.ToString() : null;
                TelecomLbs = terminalDict.TryGetValue("telecom_lbs", out var telecomLbs) ? telecomLbs?.ToString() : null;
                TelecomLbsSignal = terminalDict.TryGetValue("telecom_lbs_signal", out var telecomLbsSignal) ? telecomLbsSignal?.ToString() : null;
            }
        }

        /// <summary>
        /// 转换为字典格式
        /// </summary>
        /// <returns>字典数据</returns>
        public Dictionary<string, object?> ToDictionary()
        {
            return new Dictionary<string, object?>
            {
                ["network_license"] = NetworkLicense,
                ["device_type"] = DeviceType,
                ["serial_num"] = SerialNum,
                ["encrypt_rand_num"] = EncryptRandNum,
                ["secret_text"] = SecretText,
                ["app_version"] = AppVersion,
                ["mobile_country_cd"] = MobileCountryCd,
                ["mobile_network_num"] = MobileNetworkNum,
                ["icc_id"] = IccId,
                ["location_cd1"] = LocationCd1,
                ["lbs_num1"] = LbsNum1,
                ["lbs_signal1"] = LbsSignal1,
                ["location_cd2"] = LocationCd2,
                ["lbs_num2"] = LbsNum2,
                ["lbs_signal2"] = LbsSignal2,
                ["location_cd3"] = LocationCd3,
                ["lbs_num3"] = LbsNum3,
                ["lbs_signal3"] = LbsSignal3,
                ["telecom_system_id"] = TelecomSystemId,
                ["telecom_network_id"] = TelecomNetworkId,
                ["telecom_lbs"] = TelecomLbs,
                ["telecom_lbs_signal"] = TelecomLbsSignal
            };
        }
    }
} 